package com.lagou.edu.util;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class BillNumUtil {
    //配置双检索单例
    private static volatile BillNumUtil billNumUtil = null;

    private BillNumUtil() {
    }

    public static BillNumUtil getInstance() {
        if (billNumUtil == null) {
            synchronized (BillNumUtil.class) {
                if (billNumUtil == null) {
                    billNumUtil = new BillNumUtil();
                }
            }
        }
        return billNumUtil;
    }

    //根据日期生成发票单据编码
    public String getBillNum() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmm");
        String format = sdf.format(new Date());
        String random = StringUtils.upperCase(RandomStringUtils.randomAlphabetic(2));
        return format + random;
    }

    //根据日期生成发票详情编码
    public String getBillDetailNum() {
        return UUID.randomUUID().toString().replace("-", "").substring(0,20);
    }
}
